package demo2;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * Date: 2025-03-03
 * Time: 12:14
 */
public class demo1 {

/*    public static List<List<Integer>> generate(int numRows) {
        List<List<Integer>> ret = new ArrayList<>();
        List<Integer> list0 = new ArrayList<>();
        list0.add(1);
        ret.add(list0);

        for (int i = 1; i < numRows; i++) {
            List<Integer> curRow = new ArrayList<>();
            curRow.add(1);

            List<Integer> preRow = ret.get(i-1);
            for (int j = 1; j < i; j++) {
                int val1 = preRow.get(j);
                int val2 = preRow.get(j-1);
                curRow.add(val1+val2);
            }
            curRow.add(1);
            ret.add(curRow);
        }
        return ret;
    }*/
    public static List<List<Integer>> generate(int numRows) {
        List<List<Integer>> ret = new ArrayList<>();
        List<Integer> list0 = new ArrayList<>();
//        首先，需要添加第一行的数据
        list0.add(1);
        ret.add(list0);

        //接下来，处理后面几行的数据
        for (int i = 1; i < numRows; i++) {
            //开头
            List<Integer> curRow = new ArrayList<>();
            curRow.add(1);
            //中间
                List<Integer> preRow = ret.get(i-1);
                for (int j = 1; j < i; j++) {
                    int val1 = preRow.get(j);
                    int val2 = preRow.get(j-1);
                    curRow.add(val1+val2);
                }
           //结尾
            curRow.add(1);
            ret.add(curRow);
        }
        return ret;
    }
    public static void main(String[] args) {

    }
}
